﻿package mortal.game.view.closedBetaGiftBagNew.panel
{
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import extend.language.*;
    import fl.data.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.closedBetaGiftBag.renderer.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.mvc.core.*;

    public class ClosedBetaGiftBagOldView extends ClosedBetaBasePanel
    {
        private var _topBg:GBitmap;
        private var _getBtn:GLoadingButton;
        private var _giftList:GTileList;
        private var _playerList:GTileList;
        private var _pageSelecter:PageSelecter;
        private var _pageTool:PageTool;
        private var _bitmap1:GBitmap;
        private var _bitmap2:GBitmap;
        private var _diamondIcon1:GBitmap;
        private var _diamondIcon2:GBitmap;
        private var _rankTitle:GBitmap;
        private var _rankBgVector:Vector.<GBitmap>;
        private var _rankIconVector:Vector.<GBitmap>;
        private var _isLoadResComl:Boolean = false;

        public function ClosedBetaGiftBagOldView()
        {
            this._pageTool = new PageTool([], 10);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildren();
            this._topBg = UIFactory.gBitmap("", 13, 36, this);
            this._bitmap1 = UIFactory.gBitmap("", 433, 183, this);
            this._bitmap2 = UIFactory.gBitmap("", 593, 183, this);
            this._diamondIcon1 = UIFactory.gBitmap("", 565, 186, this);
            this._diamondIcon2 = UIFactory.gBitmap("", 738, 186, this);
            pushUIToDisposeVec(UIFactory.bg(10, 220, 658, 373, this, ImagesConst.PanelBg));
            pushUIToDisposeVec(UIFactory.bg(668, 220, 240, 373, this, ImagesConst.PanelBg));
            pushUIToDisposeVec(UIFactory.gTextField("1000", 526, 183, 50, 26, this, GlobalStyle.textFormatBai));
            pushUIToDisposeVec(UIFactory.gTextField("1000", 698, 183, 50, 26, this, GlobalStyle.textFormatBai));
            pushUIToDisposeVec(UIFactory.bg(666, 265, 245, 25, this, ImagesConst.RegionTitleBg));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(90402), 698, 267, 100, 20, this, GlobalStyle.textFormatBai.center()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(90403), 798, 267, 50, 20, this, GlobalStyle.textFormatBai.center()));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(90404), 848, 267, 50, 20, this, GlobalStyle.textFormatBai.center()));
            this._getBtn = UIFactory.gLoadingButton(ResFileConst.ClosedBetaGiftBagBtn, 763, 164, 141, 50, this);
            this._getBtn.filterEnabled = Cache.instance.closedBetaGiftBag.isGetToday == 1;
            this._rankTitle = UIFactory.gBitmap("", 653, 186, this);
            this._rankBgVector = new Vector.<GBitmap>;
            this._rankIconVector = new Vector.<GBitmap>;
            var _loc_1:int = 0;
            while (_loc_1 < 3)
            {
                
                this._rankBgVector[_loc_1] = UIFactory.gBitmap("", 676, 295 + _loc_1 * 25, this);
                this._rankBgVector[_loc_1].visible = false;
                this._rankIconVector[_loc_1] = UIFactory.gBitmap("", 670, 287 + _loc_1 * 25, this);
                this._rankIconVector[_loc_1].visible = false;
                _loc_1++;
            }
            this._giftList = UIFactory.tileList(13, 224, 680, 360, this);
            this._giftList.setStyle("cellRenderer", ClosedBetaGiftBagRenderer);
            this._giftList.columnWidth = 127;
            this._giftList.rowHeight = 180;
            this._giftList.direction = GBoxDirection.VERTICAL;
            this._giftList.dataProvider = new DataProvider(LevelRewardConfig.instance.allClosedBetaGiftBagData);
            this._giftList.drawNow();
            this._playerList = UIFactory.tileList(668, 290, 250, 270, this);
            this._playerList.setStyle("cellRenderer", ClosedBetaPlayerRenderer);
            this._playerList.columnWidth = 272;
            this._playerList.rowHeight = 25;
            this._playerList.direction = GBoxDirection.VERTICAL;
            this._pageSelecter = UIFactory.pageSelecter(718, 558, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.InputDisablBg, GlobalStyle.textFormatBai.center());
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.currentPage = 1;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onListPageChange);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onClickGetBtn);
            Dispatcher.addEventListener(EventName.ClosedBetaGiftBagFlyToPack, this.onClosedBetaGiftBagFlyToPack);
            LoaderHelp.addResCallBack(ResFileConst.closedBetaGiftBag, this.onResLoadCompl);
            return;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            super.dispose(param1);
            this._topBg.dispose(param1);
            this._bitmap1.dispose(param1);
            this._bitmap2.dispose(param1);
            this._diamondIcon1.dispose(param1);
            this._diamondIcon2.dispose(param1);
            this._getBtn.dispose(param1);
            this._giftList.dispose(param1);
            this._playerList.dispose(param1);
            this._pageSelecter.dispose(param1);
            this._rankTitle.dispose(param1);
            var _loc_2:int = 0;
            while (_loc_2 < 3)
            {
                
                this._rankBgVector[_loc_2].dispose(param1);
                this._rankBgVector[_loc_2] = null;
                this._rankIconVector[_loc_2].dispose(param1);
                this._rankIconVector[_loc_2] = null;
                _loc_2++;
            }
            this._rankBgVector = null;
            this._rankIconVector = null;
            this._topBg = null;
            this._bitmap1 = null;
            this._bitmap2 = null;
            this._diamondIcon1 = null;
            this._diamondIcon2 = null;
            this._getBtn = null;
            this._giftList = null;
            this._playerList = null;
            this._pageSelecter = null;
            this._rankTitle = null;
            this._isLoadResComl = false;
            LoaderHelp.removeResEvent(ResFileConst.closedBetaGiftBag, this.onResLoadCompl);
            Dispatcher.removeEventListener(EventName.ClosedBetaGiftBagFlyToPack, this.onClosedBetaGiftBagFlyToPack);
            Dispatcher.removeEventListener(EventName.ClosedBetaGiftBagFlyToPack, this.onClosedBetaGiftBagFlyToPack);
            return;
        }// end function

        private function onResLoadCompl() : void
        {
            this._topBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagBg3);
            this._bitmap1.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagTxt2);
            this._bitmap2.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagTxt3);
            this._diamondIcon1.bitmapData = GlobalClass.getBitmapData(ImagesConst.Yuanbao_bind);
            this._diamondIcon2.bitmapData = GlobalClass.getBitmapData(ImagesConst.Yuanbao_bind);
            this._rankTitle.bitmapData = GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagRankTxt);
            var _loc_1:int = 0;
            while (_loc_1 < 3)
            {
                
                this._rankBgVector[_loc_1].bitmapData = GlobalClass.getBitmapData("ClosedBetaGiftBagRankTxt" + ((_loc_1 + 1)).toString());
                this._rankIconVector[_loc_1].bitmapData = GlobalClass.getBitmapData("ClosedBetaGiftBagRankField" + ((_loc_1 + 1)).toString());
                _loc_1++;
            }
            this._isLoadResComl = true;
            return;
        }// end function

        private function onListPageChange(event:Event = null) : void
        {
            var _loc_2:Boolean = false;
            if (this._pageSelecter.currentPage == 1)
            {
                _loc_2 = true;
            }
            var _loc_3:int = 0;
            while (_loc_3 < 3)
            {
                
                this._rankBgVector[_loc_3].visible = _loc_2;
                this._rankIconVector[_loc_3].visible = _loc_2;
                _loc_3++;
            }
            this._playerList.dataProvider = new DataProvider(this._pageTool.getByPageNo(this._pageSelecter.currentPage));
            this._playerList.drawNow();
            return;
        }// end function

        public function updatePlayerList(param1:Array) : void
        {
            this._pageTool.array = param1;
            this._pageSelecter.maxPage = this._pageTool.pagesCount;
            this.onListPageChange();
            return;
        }// end function

        private function onClosedBetaGiftBagFlyToPack(event:DataEvent) : void
        {
            if (isDisposed)
            {
                return;
            }
            if (!this._isLoadResComl)
            {
                return;
            }
            var _loc_2:* = event.data as int;
            if (_loc_2 != 0)
            {
                return;
            }
            var _loc_3:* = new Point(663, 164);
            FlyToNavbarTool.flyToBackPack(GlobalClass.getBitmapData(ImagesConst.ClosedBetaGiftBagItem), _loc_3);
            return;
        }// end function

        private function onClickGetBtn(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.ClosedBetaGiftBagGetReward, 0));
            return;
        }// end function

        override public function refresh() : void
        {
            if (Cache.instance.closedBetaGiftBag.isGetToday == 0)
            {
                this._getBtn.enabled = true;
                EffectManager.glowFilterReg(this._getBtn);
            }
            else
            {
                EffectManager.glowFilterUnReg(this._getBtn);
                this._getBtn.filterEnabled = false;
            }
            this._giftList.dataProvider = new DataProvider(LevelRewardConfig.instance.allClosedBetaGiftBagData);
            this._giftList.drawNow();
            return;
        }// end function

    }
}
